﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Empires.BLL.Core.IService;
using Empires.CRL.DataContract;
using Empires.CRL.Tools;
using System.Web;
using Empires.BLL.ServerProvider;

namespace Empires.BLL.Core.Implement
{
    public class CompanyAboutService : ICompanyAboutService
    {
        public List<DefaultDataPack> GetAboutInfo(string copName)
        {
            RAL.Access.ICompanyAboutAccess service = new RAL.Pump.CompanyAboutDataPump();
            return service.GetAubotInfo(copName);
        }

        public bool UpdateAboutInfo(string copName, AboutDataPack pack)
        {
            if (HttpContext.Current.Request.Files.Count > 0)
            {
                if (HttpContext.Current.Request.Files["AboutUsImg"].ContentLength > 0)
                {
                    string fileName = HttpContext.Current.Request.Files["AboutUsImg"].FileName;
                    string extendName = fileName.Substring(fileName.IndexOf('.') + 1).ToLower();
                    if (extendName == "jpg" || extendName == "png")
                    {
                        pack.AboutUsImg = Tools.UploadFiles(
                            new List<UploadFileDataPack>() { 
                                new UploadFileDataPack(){
                                    BasePath = String.Format( Utils.ReadAppSetting("CustomerFile"),copName ),
                                    TypeFilter = new List<FileType>(){ FileType.jpg, FileType.png } ,
                                    UploadName = "AboutUsImg"
                                }
                            }, System.Web.HttpContext.Current.Request.Files)["AboutUsImg"];
                        pack.AboutUsImg = String.Format("<img src=\"{0}\" />", pack.AboutUsImg);
                    }
                    else
                    {
                        pack.AboutUsImg = string.Empty;
                    }
                }  
            }
            string regexp = "<script.*?</scirpt>";
            pack.AboutContent = pack.AboutContent.GetStringWithoutHTMLLabel(regexp);
            pack.Faith = pack.Faith.GetStringWithoutHTMLLabel(regexp);
            pack.Professional = pack.Professional.GetStringWithoutHTMLLabel(regexp);
            pack.Qualification = pack.Qualification.GetStringWithoutHTMLLabel(regexp);
            RAL.Access.ICompanyAboutAccess service = new RAL.Pump.CompanyAboutDataPump();
            return service.UpdateAboutInfo(copName, pack);
        }
    }
}
